/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.hogent.designpatterns.billenkar.commands;

import be.hogent.designpatterns.billenkar.Billenkar;
import be.hogent.designpatterns.billenkar.BillenkarVerzameling;
import be.hogent.designpatterns.billenkar.GemotoriseerdeBillenkar;
import be.hogent.designpatterns.billenkar.GroteBillenkar;
import be.hogent.designpatterns.billenkar.KleineBillenkar;
import be.hogent.designpatterns.billenkar.decorators.MetBluts;
import be.hogent.designpatterns.billenkar.decorators.MetKrassen;
import be.hogent.designpatterns.billenkar.decorators.MetPlatteBand;
import be.hogent.designpatterns.billenkar.decorators.MetRoest;
import java.util.Scanner;

/**
 *
 * @author Jeroen
 */
public class VoegBillenkarToeCommand implements Command {
    private BillenkarVerzameling billenkarVerzameling;
    private Command[] basisKarCommands;
    
    private Scanner in = new Scanner(System.in);
    private Billenkar kar;

    public VoegBillenkarToeCommand(BillenkarVerzameling billenkarVerzameling) {
        this.billenkarVerzameling = billenkarVerzameling;
        basisKarCommands = new Command[3];
        basisKarCommands[0] = new VoegGroteBillenkarToeCommand();
        basisKarCommands[1] = new VoegKleineBillenkarToeCommand();
        basisKarCommands[2] = new VoegGemotoriseerdeBillenkarToeCommand();
    }

    public void execute()
    {
        int basis = doeBasisMenu();
        while(basis == -1) {
            System.out.println("ONGELDIGE KEUZE!");
            basis = doeBasisMenu();
        }
        basisKarCommands[basis-1].execute();
        KiesMankementenCommand mankementCommand = new KiesMankementenCommand(kar);
        mankementCommand.execute();
        billenkarVerzameling.voegBillenkarToe(mankementCommand.getBillenkar());
        (new HoofdMenuCommand(billenkarVerzameling)).execute();
    }

    private int doeBasisMenu()
    {
         System.out.println("****************************************************");
         System.out.println("                 VOEG BILLENKAR TOE");
         System.out.println("****************************************************");
         System.out.println("");
         System.out.println("");
         System.out.println("-----------------KIES BASISMODEL-------------------");
         System.out.println("1. Groot ");
         System.out.println("2. Klein ");
         System.out.println("3. Gemotoriseerd ");
         String inv = in.nextLine();
         int keuze;
         try {
             keuze = Integer.parseInt(inv);
             if(keuze<1 || keuze>3) {
                 throw new NumberFormatException();
             }
         } catch (NumberFormatException e) {
             keuze = -1;
         }
         return keuze;
    }


    public class VoegGemotoriseerdeBillenkarToeCommand implements Command {
        public void execute()
        {
            kar = new GemotoriseerdeBillenkar();
        }
    }
    public class VoegGroteBillenkarToeCommand implements Command {
        public void execute()
        {
            kar = new GroteBillenkar();
        }
    }
    public class VoegKleineBillenkarToeCommand implements Command {
        public void execute()
        {
            kar = new KleineBillenkar();
        }
    }

}
